SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.aspnet_Membership_GetNumberOfUsersOnline
	@ApplicationName            nvarchar(256),
	@MinutesSinceLastInActive   int,
	@CurrentTimeUtc             datetime
AS
	BEGIN
		DECLARE @DateActive datetime
		SELECT  @DateActive = DATEADD(minute,  -(@MinutesSinceLastInActive), @CurrentTimeUtc)

		DECLARE @NumOnline int
		SELECT  @NumOnline = COUNT(*)
		FROM    dbo.aspnet_Users u WITH (NOLOCK),
				dbo.aspnet_Applications a WITH (NOLOCK),
				dbo.aspnet_Membership m WITH (NOLOCK)
		WHERE   u.ApplicationId = a.ApplicationId                  AND
				LastActivityDate > @DateActive                     AND
				a.LoweredApplicationName = LOWER(@ApplicationName) AND
				u.UserId = m.UserId
		RETURN(@NumOnline)
	END
GO
